fix(web): use session flavor label in voice context formatters#1
Draft
heavygee wants to merge 1 commit into
Draft
fix(web): use session flavor label in voice context formatters#1heavygee wants to merge 1 commit into
heavygee wants to merge 1 commit into
Conversation
e68ef31 to
8179263
Compare
Replaces hardcoded 'Claude Code' strings in voice context injections with the active session's flavor label (Cursor, Codex, Gemini, etc.) via getFlavorLabel() from @hapi/protocol. Falls back to 'coding agent' for unknown or missing flavors. Threads an agentLabel param through formatMessage, formatPermissionRequest, formatReadyEvent, formatNewMessages, formatHistory, and formatSessionFull. voiceHooks resolves the label once per call via session.metadata.flavor. Fixes tiann#680 via [HAPI](https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run>
8179263 to
9402685
Compare
This was referenced Jun 2, 2026
heavygee
added a commit
that referenced
this pull request
Jun 5, 2026
The native-fallback probe previously returned true whenever FCM was
configured AND devices were registered, which suppressed web-push for
the namespace. The HAPI Bot correctly pointed out the gap: if the FCM
pipeline silently breaks (expired service-account key, sustained 5xx,
OAuth token-fetch failure, network blackhole) the operator gets nothing
on either channel until they manually intervene.
Approach (deliberate, not the bot's exact suggested fix):
- FcmService now keeps a small rolling window (last 8 outcomes) of send
attempts and exposes `isHealthy()`. The threshold is 5+/8 failures =
unhealthy; the buffer starts empty so a freshly-booted hub is
optimistic ("innocent until proven guilty") and does not double-fire
on event #1.
- Token-fetch failure (`getFcmAccessToken` throws) now records exactly
one health-failure (not one per device), short-circuits the send
loop, and returns a result so `sendToNamespace` no longer leaks the
exception.
- `invalid` token responses are explicitly excluded from the health
buffer because they are per-device facts (rotated/uninstalled token),
not pipeline failures - FCM was reachable, it just rejected one
stale token.
- `buildNativeFallbackProbe` now optionally accepts the FcmService and
short-circuits to "let web-push fire" when health is bad, before it
even queries the device registry. The single-arg call shape is still
supported for back-compat.
Why not the bot's exact suggestion ("invert: call FCM first, fall back
on result.sent === 0"):
- Couples PushNotificationChannel to FcmService and FcmSendPayload,
reversing the clean parallel-channel architecture established earlier
in this PR.
- Treats every transient single-event failure as fallback-worthy, which
re-opens the duplicate-notification race that the suppression logic
was added to close (FCM HTTP timeout that delivers later + the web
push we sent in the meantime = two pings).
- A rolling health window only flips on sustained breakage, which is
the actual operational scenario the bot is worried about.
The wrist-first design intent ("FCM fires unconditionally, web-push is
suppressed for the same namespace") documented in
docs/api/native-companion-contract.md is preserved on the happy path.
The probe only re-enables web-push when there is concrete evidence the
native pipeline is not delivering.
Tests:
- New FcmService.isHealthy suite covers empty-buffer, threshold flip,
recovery as failures age out of the window, invalid-token exclusion,
and network-error path.
- nativeFallbackProbe gains coverage for the unhealthy-but-registered,
healthy-and-registered, and absent-fcmService (back-compat) cases.
- All 292 hub tests still pass; typecheck clean.
Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces hardcoded
Claude Codestrings in voice context injections with the active session's flavor label (Cursor, Codex, Gemini, OpenCode, etc.) sourced fromgetFlavorLabel()in@hapi/protocol. Falls back tocoding agentfor unknown or missing flavors.web/src/realtime/hooks/contextFormatters.ts— threadsagentLabel(optional, default'coding agent') throughformatPlainText,formatPermissionRequest,formatMessage(text blocks + tool-call lines),formatNewMessages,formatHistory,formatSessionFull,formatReadyEvent.web/src/realtime/hooks/voiceHooks.ts— addsgetAgentLabel(session)helper usinggetFlavorLabel()from@hapi/protocol; passes label into all formatter calls.Why shared/src/voice.ts is not touched
The system prompt in
voice.tscontains example text that references "Claude" (e.g. the permission request example:"Claude wants to run a bash command"). We considered updating this but deliberately chose not to.The argument for changing it: be as accurate as possible even in the ConvAI prompt.
The argument against, which won: once this PR (and tiann#682) are merged, every context update ConvAI receives will carry the correct agent label — "Cursor is requesting permission to use Bash", not "Claude Code is requesting...". At that point ConvAI's spoken responses will naturally reflect the right terminology, because LLMs follow the context they receive rather than parroting example text from a system prompt verbatim. The
voice.tswording only remains a real-world problem if these formatter fixes are not in place — which is an argument for merging this PR, not for also editing the system prompt. Touching system prompt wording without that being strictly necessary felt like stepping into editorial territory that belongs to the maintainers.Happy to follow up separately on
voice.tsif desired once these changes land.Test plan
bun test web/src/realtime/hooks/contextFormatters.test.ts(8 tests — all assert label appears, none hardcodeClaude Code)Issues
Fixes tiann#680